package a09_贪心算法;

/**
 * <p>
 * a13_柠檬水找零复习3
 * </p>
 *
 * @author flyduck
 * @since 2025/4/16
 */
public class a13_柠檬水找零复习3 {
    public boolean lemonadeChange(int[] bills) {
        int five = 0;
        int ten = 0;
        int twenty = 0;

        for (int bill : bills) {
            if(bill == 5){
                five++;
            }else if(bill == 10){
                if(five == 0){
                    return false;
                }
                five--;
                ten++;
            }else {//20
                //先使用十元
                if (ten > 0 && five > 0) {
                    ten--;
                    five--;
                    twenty++;
                }else if(five >= 3){
                    five -= 3;
                    twenty++;
                }else {
                    return false;
                }
            }
        }

        return true;
    }
}
